package gold.digger;

import gold.vo.ListNode;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC141 {

    public boolean hasCycle(ListNode head) {
        if (null == head) {
            return false;
        }

        ListNode fast = head.next, slow = head;
        while (fast != null && fast.next != null && fast != slow) {
            slow = slow.next;
            fast = fast.next.next;//step two forward;
        }

        return fast == slow;
    }


    public static void main(String[] args) {
        LC141 an = new LC141();
        ListNode head = ListNode.createList("3->2->0->4");
        System.out.println(an.hasCycle(head));
    }
}
